//
//  TipTableViewController.m
//  ICup
//
//  Created by liao Echo on 14-10-12.
//  Copyright (c) 2014年 Echo. All rights reserved.
//

#import "TipTableViewController.h"

@interface TipTableViewController ()

@end

@implementation TipTableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 44;
    }else{
        return 80;
    }
}
-(CGFloat)tableView:(UITableView *)aTableView heightForHeaderInSection:(NSInteger)section {
    return 20;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  2;
}

- (UITableViewCell *)tableView:(UITableView *)tableview cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *CellIdentifier = @"SettingBaseCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.backgroundColor = [UIColor clearColor];//ios7必须要这样处理，不然默认会是白色
    
    if (indexPath.row == 0) {
       cell.textLabel.text = @"提醒";
        UISwitch *switchBtn = [[UISwitch alloc] init];
        cell.accessoryView = switchBtn;
        if (![[NSUserDefaults standardUserDefaults] boolForKey:ICUP_CLOSE_TIXING]) {
            [switchBtn setOn:YES];
        }else{
            [switchBtn setOn:NO];
        }
        [switchBtn addTarget:self action:@selector(onSwitchValueChanged:) forControlEvents:UIControlEventValueChanged];
    }else if(indexPath.row == 1){
        cell.textLabel.font = [UIFont systemFontOfSize:16];
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.textColor = [UIColor grayColor];
        cell.textLabel.text = @"只有开启了提醒功能，icup才会提醒你在合适的时间喝水，默认是开启的，修改该设置将会下次同步饮水数据后起效。";
    }
    return cell;
}
-(IBAction)onSwitchValueChanged:(UISwitch*)sender{
    [[NSUserDefaults standardUserDefaults] setBool:!sender.on forKey:ICUP_CLOSE_TIXING];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

@end
